<?php
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
include('/var/www/html/new/d/module/api/function.class.php');
include_once '/var/www/html/new/d/meituan/MT.class.php';
$meituan = new Meituan();
$url = 'http://lvyou.meituan.com/rhone/lv/order/refund/notice'; //美团退款通知地址
$pftorder = $_REQUEST['ordern'];
$partnerId = $_REQUEST['partnerId'];
$meituan->logfile(json_encode($_REQUEST),"refundnotice");
$PFT_infunction = new AllFunction();
$pft_order_xml = $PFT_infunction->Select_PFTorder($pftorder);

$UUaids = (int)$pft_order_xml->Rec->UUaids; 
if($UUaids == 0){
	$UUsellid = (string)$pft_order_xml->Rec->UUsellid;
}
else $UUsellid = (string)$pft_order_xml->Rec->UUaid;

$sql = "select supplierIdentity,signkey from uu_qunar_use  where DockingMode = 1 and fid =$UUsellid limit 1";
$GLOBALS['le']->query($sql); 
$GLOBALS['le']->fetch_assoc();
$signkey = explode("|",$GLOBALS['le']->f('signkey'));
$clientID = $signkey[0];
$clientsecret = $signkey[1];

date_default_timezone_set('GMT');
$date = date('D, d M Y H:i:s e', time());
date_default_timezone_set('PRC');
$authorization = buildSign('POST',$date,$clientID,$clientsecret);

$header = array(
	"Content-Type: application/json; charset=utf-8",
	"Date:" . $date,
	"PartnerId:" . $partnerId,
	"Authorization:" . $authorization,
);

$refundnotice = array(
	'code'=>0,
	'describe'=>'退款成功',
	'partnerId'=>$partnerId
);
$data = json_encode($refundnotice);
// echo $data;exit;
$a = mt_notice_post($data,$header,$url);
$meituan->logfile(json_encode($_REQUEST).'|'.$a,"refundnotice");
function mt_notice_post($data,$header,$url){ //美团提供的消费地址
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	$result=  curl_exec($ch); 
	curl_close($ch);
	return $result;
}

function buildSign($method,$date,$clientID,$clientsecret){
	$string_to_sign = $method . ' ' . '/rhone/lv/order/refund/notice' . "\n" . $date;
	$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $clientsecret, true));
	$authorization = 'MWS ' . $clientID . ':' . $signature;
	return $authorization;	
}
?>